# 客户端 (client.py)
import socket


def start_client():
    # 创建socket对象
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # 获取本地主机名
    host = socket.gethostname()
    port = 9999

    # 连接服务器
    client_socket.connect((host, port))

    # 接收服务器消息
    msg = client_socket.recv(1024)
    print(f"服务器消息: {msg.decode('utf-8')}")

    # 向服务器发送消息
    client_socket.send("你好，服务器！".encode('utf-8'))

    # 关闭连接
    client_socket.close()


if __name__ == '__main__':
    start_client()